﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IBupro.Models.StudentProjectSearchModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%: Html.Translate("studentProjects") %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%Html.RenderPartial("SearchTabs", new {page="student"}); %>

<script type="text/javascript">

    $(function () {
        $(".autocomplete").autocomplete({
            source: function (request, response) {
                $.getJSON("/Tag/List", {
                    term: extractLast(request.term)
                }, response);
            },
            search: function () {
                // custom minLength
                var term = extractLast(this.value);
                if (term.length < 1) {
                    return false;
                }
            },
            focus: function () {
                // prevent value inserted on focus
                return false;
            },
            select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            },
            selectFirst: function () {
                // prevent value inserted on focus
                return true;
            },
            change: function (event, ui) {
                //if the value of the textbox does not match a suggestion, clear its value
                if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
                    $(this).val('');
                }
            }
        }).live('keydown', function (e) {
            var keyCode = e.keyCode || e.which;
            //if TAB or RETURN is pressed and the text in the textbox does not match a suggestion, set the value of the textbox to the text of the first suggestion
            if ((keyCode == 9 || keyCode == 13) && ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0)) {
                $(this).val($(".ui-autocomplete li:visible:first").text());
            }


        });
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }
    });
    </script>
    

    <h2><%: Html.Translate("studentProjects") %></h2>
<% using (Html.BeginForm()) {%>
 <div><%:Html.TextBoxFor(model => model.SearchString, new {@class="autocomplete" })%></div>
    <div>
        <span><%: Html.Translate("studentField") %><%:Html.DropDownList("StudentFieldId",Model.GetStudentFieldList()) %></span>
        <span><%: Html.Translate("subject") %><%:Html.DropDownList("SubjectId", Model.GetSubjectList(), new { @onchange = "this.form.submit();" })%></span>
        <span><%: Html.Translate("freeOnly") %><%:Html.CheckBoxFor(model => model.FreeOnly) %></span>
    </div>
    <div>
        <span><input type="submit" value="<%: Html.Translate("search")%>"/></span>
    </div>
    <%} %>

    <table>
        <thead>
        <tr>
            <th></th>
            <th>
                <%:Html.Translate("name") %>
            </th>
            <th>
                <%:Html.Translate("details") %>
            </th>
            <th>
                <%:Html.Translate("created") %>
            </th>
            <th>
                <%:Html.Translate("shortcut") %>
            </th>
            <th>
                <%:Html.Translate("memberCount") %>
            </th>
            <th>
                <%:Html.Translate("subject") %>
            </th>
            <th>
                <%:Html.Translate("locked") %>
            </th>
            <th></th>
        </tr>
        </thead>

        <tbody>
        <% foreach (var item in Model.ProjectList) { %>
    
            <tr>
               <td>
                    <%: Html.ActionLink(Html.Translate("details"), "Detail","StudentProject", new { id=item.Id },null)%>
                </td>
                <td>
                    <%: item.Name %>
                </td>
                <td>
                    <%: Html.TruncateDetail(item.Detail) %>
                </td>
                <td>
                    <%: String.Format("{0:g}", item.Created) %>
                </td>
                <td>
                    <%: item.Shortcut %>
                </td>
                <td>
                     <%:item.Users.Count %> <%:Html.Translate("of") %> <%: item.MemberCount %>
                </td>
                <td>
                    <%: item.Subject == null ? "" : item.Subject.Shortcut%>
                </td>
                <td>
                    <%: Html.Translate(item.Locked.ToString())%>
                </td>
                 <td>
                    <%if (User.IsInRole("Student"))
                    {%>
                    <%:Html.ActionLink(Html.Translate("subscribe"), "SendSubscriptionRequest", "StudentProject",
                                      new {id = item.Id}, null)%>
                    <%
                    }%>

                </td>
            </tr>
    
        <% } %>
        </tbody>
    </table>

</asp:Content>

